//========================================================================
//Copyright 2007-2010 David Yu dyuproject@gmail.com
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at 
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================

package com.dyuproject.kvstore;

import java.util.List;
import java.util.Map.Entry;

import com.google.common.base.Function;

/**
 * A CompositeStore wraps a {@link Store store} in w/c all method calls are forwarded to.
 * Subclassing this class for customization is the general idea.
 *
 * @author David Yu
 * @created Feb 5, 2010
 */
public abstract class CompositeStore<T> extends AbstractStore<T>
{
    
    protected final Store<T> store;

    public CompositeStore(Store<T> store)
    {
        super(store.getSerializer());
        this.store = store;
    }

    public void put(String key, T value)
    {
        store.put(key, value);
    }

    public void delete(String key)
    {
        store.delete(key);
    }

    public void delete(List<String> keys)
    {
        store.delete(keys);
    }

    public <V> V get(String key, Serializer<V> serializer)
    {
        return store.get(key, serializer);
    }

    public T mutate(String key, Function<? super T, ? extends T> mutator)
    {
        return store.mutate(key, mutator);
    }

    public T mutate(String key, Function<? super T, ? extends T> mutator, int maxRetries)
    {
        return store.mutate(key, mutator, maxRetries);
    }

    public T mutateRaw(Mutable<String> mutableKey, Function<? super byte[], ? extends T> mutator)
    {
        return store.mutateRaw(mutableKey, mutator);
    }

    public T mutateRaw(Mutable<String> mutableKey, Function<? super byte[], ? extends T> mutator, int maxRetries)
    {
        return store.mutateRaw(mutableKey, mutator, maxRetries);
    }

    public <V> List<V> get(List<String> keys, Serializer<V> serializer)
    {
        return store.get(keys, serializer);
    }

    public <V> List<Entry<String, V>> getEntries(List<String> keys, Serializer<V> serializer)
    {
        return store.getEntries(keys, serializer);
    }
    
    public <V> List<Entry<String, V>> scanEntries(String start, String end, int max, Serializer<V> serializer)
    {
        return store.scanEntries(start, end, max, serializer);
    }

    public <V> List<Entry<String, V>> scanEntriesReverse(String start, String end, int max, Serializer<V> serializer)
    {
        return store.scanEntriesReverse(start, end, max, serializer);
    }

    public <V> List<V> scan(String start, String end, int max, Serializer<V> serializer)
    {
        return store.scan(start, end, max, serializer);
    }

    public <V> List<V> scanReverse(String start, String end, int max, Serializer<V> serializer)
    {
        return store.scanReverse(start, end, max, serializer);
    }

    public List<String> keyScan(String start, String end, int max)
    {
        return store.keyScan(start, end, max);
    }

    public List<String> keyScanReverse(String start, String end, int max)
    {
        return store.keyScanReverse(start, end, max);
    }

}
